package com.ctsi.framework.mybatis.dialect;

import java.sql.PreparedStatement;
import java.sql.SQLException;


/**
 * H2数据库分页方言
 * 
 * @author zhangjw
 */
public class H2Dialect extends AbstractMiDialect {



	@Override
	public void setLimitParamters(PreparedStatement ps, int parameterSize,
			int offset, int limit) throws SQLException {
		if(offset > 0){
			ps.setInt(parameterSize + 1, limit);
			ps.setInt(parameterSize + 2, offset);
		}else{
			ps.setInt(parameterSize + 1, limit);
		}
		
	}

	@Override
	public String getLimitString(String sql, int offset) {
		 return new StringBuilder(sql.length() + 20).
		            append(sql).
		            append(offset > 0 ? " limit ? offset ?" : " limit ?").
		            toString();
	}

	@Override
	public boolean supportsLimitOffset() {
		
		return true;
	}
   
}